<%@ page import="gdepot.Orders" %>
<%@ page import="gdepot.OrderStatus" %>
<!DOCTYPE html>
<html>
<head>
    <meta name="layout" content="main">
    <g:set var="entityName" value="${message(code: 'orders.label', default: 'Orders')}"/>
    <title><g:message code="default.list.label" args="[entityName]"/></title>
</head>
<body>
<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li>Mine Order</li>
        </ol>
    </div>
</div>
<g:if test="${flash.message}">
    <div class="alert alert-warning">
        <a href="#" class="close" data-dismiss="alert">
        &times;
        </a>
        <strong>${flash.message}</strong>
    </div>
</g:if>

<div class="row">
    <div class="container">

        <table class="table table-striped table-bordered">
            <thead>
            <tr>
                <th><g:message code="orders.goods"/></th>
                <th><g:message code="orders.receiver.address"/></th>
                <g:sortableColumn property="price" titleKey="orders.price"
                                  params="${[status: params.status]}"/>
                <g:sortableColumn property="orderDate" titleKey="orders.orderDate"
                                  params="${[status: params.status]}"/>
                <g:sortableColumn property="shipDate" titleKey="orders.shipDate"
                                  params="${[status: params.status]}"/>
                <g:sortableColumn property="orders.status " titleKey="订单状态"/>
                <g:sortableColumn property="orders.id" titleKey="操作"/>
            </tr>
            </thead>
            <tbody>
            <g:each in="${orderList}" status="i" var="orders">
                <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                    <td>
                        <p><g:message code="orders.containsGoods"/>:</p>

                        <p>
                        <ul>
                            <g:each in="${orders.cart?.lineItems}" var="lineItem">
                                <li>
                                    <g:link controller="goods" action="show" id="${lineItem.goods?.id}">
                                        ${lineItem.goods?.title}
                                    </g:link>
                                    *
                                    ${lineItem.itemNumber}
                                </li>
                            </g:each>
                        </ul>
                    </p>
                    </td>
                    <td>
                        <g:message code="orders.receiver"/>:
                        ${fieldValue(bean: orders, field: 'receiverName')}<br/>
                        <g:message code="orders.phone"/>:
                        ${fieldValue(bean: orders, field: 'phone')}<br/>
                        <g:message code="orders.address"/>:
                        ${fieldValue(bean: orders, field: 'address')}<br/>
                    </td>
                    <td>${fieldValue(bean: orders, field: 'price')}</td>
                    <td><g:formatDate format="yyyy-MM-dd" date="${orders.orderDate}"/></td>
                    <td><g:formatDate format="yyyy-MM-dd" date="${orders.shipDate}"/></td>
                    <td>
                    %{--TOBEPAID,SHIPPED,CANCELED,SUCCESS,FAILED,CLOSE--}%
                        <g:if test="${orders.status == gdepot.OrderStatus.TOBEPAID}">
                            <g:message code="orders.status.tobepaid"/>

                        </g:if>
                        <g:elseif test="${orders.status == gdepot.OrderStatus.SHIPPED}">
                            <g:message code="orders.status.shipped"/>
                            <g:form action="markAsReceived" method="POST">
                                <input type="hidden" name="id" value="${orders.id}}"/>
                                <input type="submit" value="${message(code: 'orders.received')}"/>
                            </g:form>
                        </g:elseif>
                        <g:elseif test="${orders.status == gdepot.OrderStatus.CLOSE}">
                            <g:message code="orders.status.close"/>
                        </g:elseif>
                        <g:elseif test="${orders.status == gdepot.OrderStatus.SUCCESS}">
                            <g:message code="order.status.success"/>
                        </g:elseif>
                        <g:elseif test="${orders.status == gdepot.OrderStatus.FAILED}">
                            <g:message code="order.status.failed"/>
                        </g:elseif>
                        <g:elseif test="${orders.status == gdepot.OrderStatus.CANCELED}">
                            <g:message code="orders.status.canceled"/>
                        </g:elseif>
                    </td>
                    <td>
                        <g:link action="show" class="btn btn-link" id="${orders?.id}">查看</g:link><br/>
                        <g:if test="${orders.status == gdepot.OrderStatus.TOBEPAID}">
                            <g:form controller="transactionRecord" action="pay">
                                <g:hiddenField name="orderId" value="${orders.id}"></g:hiddenField>
                                <g:submitButton class="btn btn-link" name="支付"></g:submitButton>
                            </g:form><br/>
                            <g:form controller="orders" method="post">

                                <g:hiddenField name="orderId" value="${orders.id}"/>
                                <g:hiddenField name="status" value="CANCELED"/>
                                <g:actionSubmit class="btn btn-link" action="changeOrderStatus" value="${message(code: '取消')}"
                                                onclick="return confirm('${message(code: '确认要修改吗？', default: 'Are you sure?')}');"/>
                            </g:form>

                        </g:if>
                        <g:elseif test="${orders.status == gdepot.OrderStatus.FAILED}">
                            <g:form controller="transactionRecord" action="pay">
                                <g:hiddenField name="orderId" value="${orders.id}"></g:hiddenField>
                                <g:submitButton  class="btn btn-link" name="继续支付"></g:submitButton>
                            </g:form><br/>
                            <input type="hidden" name="id" value="${orders.id}}"/>
                            <g:form controller="orders" method="post">
                                ${orders.id}
                                <g:hiddenField name="orderId" value="${orders.id}"/>
                                <g:hiddenField name="status" value="CANCELED"/>
                                <g:actionSubmit action="changeOrderStatus" value="${message(code: '取消')}"
                                                onclick="return confirm('${message(code: '确认要修改吗？', default: 'Are you sure?')}');"/>
                            </g:form>
                        </g:elseif>
                        <g:elseif test="${orders.status == gdepot.OrderStatus.SHIPPED}">
                            <g:message code="orders.status.shipped"/>
                            <g:form action="'changeOrderStatus" method="POST">
                                <input type="hidden" name="id" value="${orders.id}}"/>
                                <input type="hidden" name="status" value="RECEIVED"/>
                                <input class="btn btn-link" type="submit" value="${message(code: 'orders.received')}"/>
                            </g:form>
                        </g:elseif>

                    </td>
                </tr>
            </g:each>
            </tbody>
        </table>

        <div class="pagination">
            <g:paginate total="${ordersInstanceCount ?: 0}"/>
        </div>
    </div>
</div>
</body>
</html>
